/**
 * Created by WT-SUN on 2017/5/11.
 */
$(function () {
    /**
     * 选择培训计划
     */
    $("#planId").textbox({
        iconWidth: 20,
        icons: [{
            iconCls: 'icon-add',
            handler: function(e){

            }
        }]
    });
    var TRAINFORM=CONSTANT.DictionaryTypeDefConstants.TRAINFORM;//培训形式
    queryComboData(TRAINFORM,'trainFormId');
    addPerson();
});
function queryComboData(code,queryId) {
    var pageId='#'+queryId;
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $(pageId).combobox({
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200'

            });
        }
    });
}

function addPerson() {
    $('#personTb').datagrid({
        fitColumns: true,
        idField: 'id',
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 300,
        url: ROOT_PATH + '/train/record/selectUserListByRecordId.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc',
            recordId:$.getQueryParam('id')
        },
        columns: [[
            {
                field: 'id', title: 'id', hidden:true,width: 20
            },
            {field: 'userId', title: 'userId', hidden:true,width: 100},
            {field: 'realName', title: '姓名', width: 100},
            {
                field: 'deptName',
                title: '工作单位',
                width: 100,
                formatter: function (value, row, index) {
                    var name = '';
                    if (row.userDepartmentList && row.userDepartmentList.length > 0) {
                        for (var index in row.userDepartmentList) {
                            if (row.userDepartmentList[index].deptName != null) {
                                name += ',' + row.userDepartmentList[index].deptName;
                            }
                        }
                        return name.substring(1);
                    } else {
                        return '';
                    }
                }
            },
            {field: 'code', title: '编号', width: 100},
            {field: 'isQualified', title: '是否合格', width: 100,
                formatter: function (value, row, index){
                    return row.isQualified=='1'?'是':(row.isQualified=='0'?'否':'');
                }
            },
            {field: 'score', title: '成绩', width: 100}
        ]],
        onLoadSuccess: function () {
            var arr= $('#personTb').datagrid('getData');
            $("#realUserNum").textbox('setText',arr.total);
        }
    });
}
